package com.woniu.service.impl;

import com.woniu.dao.RolepermissionDao;
import com.woniu.pojo.Rolepermission;
import com.woniu.pojo.RolepermissionExample;
import com.woniu.service.RolepermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;

@Service
@Transactional
public class RolepermissionServiceImpl implements RolepermissionService {
    @Autowired
    private RolepermissionDao rolepermissionDao;
    @Override
    public void assignPermission(Integer rid, Integer[] pids) {
        //将rid对应的许可删除
        RolepermissionExample example = new RolepermissionExample();
        example.createCriteria().andRidEqualTo(rid);
        rolepermissionDao.deleteByExample(example);
        //将rid对应新的许可添加
        for(Integer pid:pids){
            Rolepermission rolepermission = new Rolepermission();
            rolepermission.setPid(pid);
            rolepermission.setRid(rid);
            rolepermissionDao.insert(rolepermission);
        }
    }
}
